import {
	getcheck,
	httpCheck
} from '../../request/check.js'
export default {
	namespace: true,
	state: {
		total: 0,
		currentPage: 1,
		data: [],
	},
	mutations: {
		init: (data, init) => data.data = init,
		total: (data, init) => data.total = init,
		pushData: (data, pD) => data.data = data.data.concat(pD),
		setPage: (data, num) => num==0 ? data.currentPage = num : data.currentPage++
	},
	actions: {
		async initData(store, type) {
			return new Promise(async (res,rej) =>{
				try{
					store.commit("setPage",0)
					store.commit('init',[])
					const result = await httpCheck(type,"getAll",{
						currentPage:store.state.currentPage,
						pageSize: 10
					})
					store.commit('init', result.records)
					store.commit('total',result.total)
					uni.showToast({
						title:`共${result.total}条记录`
					})
					res(result.total);
				}catch(e){
					
				}
			})
		},
		async getData(store, type){
			store.commit("setPage")
			const result = await httpCheck(type,"getAll",{
				currentPage:store.state.currentPage,
				pageSize: 10
			})
			store.commit("pushData",result.records)
		}
	}
}
